package cn.yiyuan.org.service.impl;

import cn.yiyuan.base.until.PageInfo;
import cn.yiyuan.org.domain.Emp;
import cn.yiyuan.org.mapper.EmpMapper;
import cn.yiyuan.org.query.DepQuery;
import cn.yiyuan.org.service.IEmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

/**
 * @user m
 * @project system
 * @date 2023-10-28
 * @package cn.yiyuan.org.service.impl
 */
//事务
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
@Service
public class EmpServiceImpl implements IEmpService {
    @Autowired
    private EmpMapper empMapper;
    @Override
    public void insert(Emp dep) {
        empMapper.insert(dep);
    }

    @Override
    public void delete(Serializable id) {
        empMapper.delete(id);
    }

    @Override
    public void update(Emp dep) {
        empMapper.update(dep);
    }

    @Override
    public List<Emp> getAll() {
        return empMapper.getAll();
    }

    @Override
    public Emp getById(Serializable id) {
        return empMapper.getById(id);
    }

    @Override
    public PageInfo<Emp> queryPage(DepQuery depQuery) {
        //查询总条数
        Long total =  empMapper.queryTotal(depQuery);
        //查询分页  数据
        //享元模式
        if (total !=0){
            List<Emp> list = empMapper.queryPage(depQuery);
            return new PageInfo<Emp>(total,list);
        }
        return new PageInfo<Emp>();
    }
}
